﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using System.Diagnostics;

public class RequestManager : BaseManager
{
    public RequestManager(GameFacade _facade) : base(_facade) { }

    private Dictionary<ActionCode, BaseRequest> requestDic = new Dictionary<ActionCode, BaseRequest>();

    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="requestCode"></param>
    /// <param name="request"></param>
    public void AddRequest(ActionCode actionCode, BaseRequest request)
    {
        requestDic.Add(actionCode, request);
    }

    /// <summary>
    /// 移除
    /// </summary>
    /// <param name="requestCode"></param>
    public void RemoveRequest(ActionCode actionCode)
    {
        requestDic.Remove(actionCode);
    }

    /// <summary>
    /// 处理服务器端的响应
    /// </summary>
    /// <param name="requestCode"></param>
    /// <param name="data"></param>
    public void HandleResponse(ActionCode actionCode, string data)
    {
        BaseRequest request = requestDic.TryGet<ActionCode, BaseRequest>(actionCode);
        if (request == null)
        {
            UnityEngine.Debug.LogWarning("无法得到RequestCode[" + actionCode + "]对应的Request类");
            return;
        }
        request.OnResponse(data);
    }
}
